package com.example.taximeter.mapper;

import com.example.taximeter.bean.FileInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 文件管理
 */
@Mapper
public interface FileInfoMapper {
    //查询文件信息（ownerid）
    @Select("select fileid, ownerid, filename, fileurl, uploadtime  from fileinfo where ownerid = #{ownerid,jdbcType=VARCHAR} order by uploadtime desc")
    List<FileInfo> findfileByOwnerid(@Param("ownerid") String ownerid);

    //查询文件信息（ownerid）
    @Select("select fileid, ownerid, filename, fileurl, uploadtime from fileinfo where fileid = #{fileid,jdbcType=VARCHAR}")
    FileInfo findfileByFileid(@Param("fileid") String fileid);

    //新增文件信息
    @Insert("insert into fileinfo (fileid,ownerid, filename, fileurl, uploadtime) values " +
            "(#{fileid,jdbcType=VARCHAR}, #{ownerid,jdbcType=VARCHAR},  #{filename,jdbcType=VARCHAR}, #{fileurl,jdbcType=VARCHAR}, #{uploadtime})")
    Boolean createFile(FileInfo fileInfo);

    //修改文件信息
    @Update("update fileinfo set fileid = #{fileid,jdbcType=VARCHAR}, ownerid = #{ownerid,jdbcType=VARCHAR},filename = #{filename,jdbcType=VARCHAR},fileurl = #{fileurl,jdbcType=VARCHAR} where fileid = #{fileid,jdbcType=VARCHAR}")
    Boolean updateFile(FileInfo fileInfo);

    //删除文件信息
    @Delete("delete from fileinfo where fileid = #{fileid,jdbcType=VARCHAR}")
    Boolean deleteFile(String fileid);

    @Update("update fileinfo \n" +
            "set filecon = #{data,jdbcType=BLOB}\n" +
            " where  fileid = #{id,jdbcType=VARCHAR}")
    boolean updateFileinfoByFileid(@Param("id") String fileid,@Param("data") byte[] data);

    //查询文件信息（ownerid）
    @Select("select fileid,fileurl from fileinfo")
    List<FileInfo> findfileinfo();
}
